package cn.cherry.mybatis.pietoken;

import org.springframework.stereotype.Component;

/**
 * @Author: SongTiankai
 * @Description: 用户切换类
 * @Date: 2023/12/31 21:13
 * @Version: 1.0
 */
@Component
public class LoginUserThreadLocal {

    private static ThreadLocal<LoginUser> THREAD_LOCAL = new ThreadLocal<>();

    /**
     * 设置上下文用户
     * @param loginUser
     */
    public static void setLocalUser(LoginUser loginUser){
        THREAD_LOCAL.set(loginUser);
    }

    /**
     * 获取用户
     * @return
     */
    public static LoginUser getLocalUser(){
        return THREAD_LOCAL.get();
    }
}
